<?php
header('Content-Type: application/json; charset=ISO-8859-1');
$con = mysql_connect("127.0.0.1","root","457812");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("cruzRoja", $con);

$nom = "";
$loc = "";

if (isset($_GET['nom']) ) $nom = $_GET['nom'];
if (isset($_GET['loc']) ) $loc = $_GET['loc'];


$sql = "select 
Nombre, Apellido, DomCodPos, upper(DomLocalidad) as 'DomLocalidad', DomTelefMovil, lat ,lon 
from rrhh where DomTelefMovil is not NULL AND upper(DomLocalidad)  like upper('%".$loc."%')  
and upper(Nombre) like upper('%".$nom."%') order by DomLocalidad";

$result = mysql_query($sql);
$i=0;
echo'{ "contactos":[';
while($row = mysql_fetch_array($result))
  {
  if ($i > 0) echo ','; 
  $i++;
  echo '{';
  echo '"apellido":"' . $row['Apellido'].'",'; 
  echo '"nombre":"' . $row['Nombre'].'",';
  echo '"domCopPos":"' , $row['DomCodPos'].'",'; 
  echo '"DomTelefMovil":"' . $row['DomTelefMovil'].'",';
  echo '"domCopPos":"' , $row['DomCodPos'] .'",'; 
  echo '"DomLocalidad":"' . $row['DomLocalidad'].'",';
  echo '"lat":"'.$row['lat'].'",';
  echo '"lon":"'.$row['lon'].'"';
  echo '}';
  }
  echo ']}';

mysql_close($con);
?> 